﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using papercut2.Data.Global;

namespace papercut2.UI
{
    /// <summary>
    /// DrawPic.xaml 的交互逻辑
    /// </summary>
    /// 
    public class Group
    {//Data member
        List<Point> curveStartPointList = new List<Point>();
        List<PointCollection> container = new List<PointCollection>();
        //Method
        public void Add(PointCollection pc)
        {
            container.Add(pc);
        }

        public void Remove(PointCollection pc)
        {
            container.Remove(pc);
        }

        //Property
        public int Count    //Read Only
        {
            get
            { return container.Count; }
        }

        public List<Point> CurveStartPoint
        {
            get
            {
                return curveStartPointList;
            }
            set
            {
                curveStartPointList = value;
            }
        }
        public List<PointCollection> PointCollectionContainer
        {
            get
            {
                return container;
            }
            set
            {
                container = value;
            }
        }
    };
    
    public partial class DrawPic : Window
    {
        //绘制结构
            //存储所有的图案
        List<Group> pictureGarage = new List<Group>();
        

        //枚举：对折类型
        enum FoldingType
        {
            Horizontal = 0, //水平
            Vertical = 1,   //垂直
            diagonal = 2,   //对角线
        }

        //Hash对照函数
        private Group Infection(Path path, Group orig)
        {
            return orig;
        }

        //标志变量

        private void PathInitialize()        	//图像显示初始化 
        {
            int i;
            foreach (Group group in pictureGarage)   //对每一个GROUP创建一个PATH并且添加到CANVASDRAWING中
            {
                Path path = new Path();
                path.Stroke = Brushes.Black;
                PathGeometry pg = new PathGeometry();
                PathFigureCollection pfc = new PathFigureCollection();

                for (i = 0; i < group.Count; i++)
                {
                    PathFigure pf = new PathFigure();
                    pf.StartPoint = group.CurveStartPoint[i];
                    // pf.IsClosed = true;
                    PathSegmentCollection psc = new PathSegmentCollection();
                    PolyBezierSegment PBSeg = new PolyBezierSegment();
                    PBSeg.Points = group.PointCollectionContainer[i];
                    psc.Add(PBSeg);
                    pf.Segments = psc;
                    pfc.Add(pf);
                }
                pg.Figures = pfc;
                path.Data = pg;
                canvasDrawing.Children.Add(path);
                //将该PATH加入HASH TABLE，与该GROUP对应
            }
        }
  
        private void PathRefresh() 			//重绘
        {}

        private void PathModify()           	//点的调整
        {}
        //------------------------------------------------------------ 
        private void CanvasFold()           	//图像对折（仅支持对角线、水平和垂直）
        {}
        //------------------------------------------------------------
        private void PathTransform()       	//整体变换（有平移、缩放等）
        {}
        //……
        //------------------------------------------------------------
        private void PathCombination()      	//图像合并
        {}
        private void PathSeperation()       	//图像打散
        {}
        //------------------------------------------------------------
        private void CtrlChooseBegin()      	//操作：开始复选
        {}
        private void CtrlChooseEnd()       	//操作：结束复选
        {}
        private void CtrlChoosing()         	//操作：复选框拉动
        {}
        //------------------------------------------------------------
        private void CtrlMoveBegin()        	//操作：开始移动
        {}
        private void CtrlMoveEnd()          	//操作：结束移动
        {}
        private void CtrlMoving()           	//操作：拖拽移动
        {}
        //------------------------------------------------------------
        private void CtrlAdd()              	//操作：添加
        {}
        private void CtrlDelete()           	//操作：删除
        { }
        //------------------------------------------------------------


        public DrawPic()                    //主程序
        {
            InitializeComponent();
            //测试数据--
            PointCollection pc = new PointCollection();
            pc.Add(new Point(200, 100));
            pc.Add(new Point(200, 400));
            pc.Add(new Point(400, 400));
            Group groupItem = new Group();
            groupItem.CurveStartPoint.Add(new Point(100, 100));
            groupItem.Add(pc);
            pictureGarage.Add(groupItem);
            //----------



            PathInitialize();
        }

        private void canvasDrawing_MouseDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void canvasDrawing_MouseMove(object sender, MouseEventArgs e)
        {

        }

        private void canvasDrawing_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }


    }
}
